<?php
/**
 * NavController
 * 
 * @author
 * @version 
 */
require_once 'Zend/Controller/Action.php';
class Admin_NavController extends Zend_Controller_Action
{
    /**
     * 导航菜单列表
     */
    public function indexAction ()
    {
    	$layout = $this->_helper->layout();
        $layout->title =  "导航菜单";   
        $layout->keywords = "导航,菜单";
        $layout->description = "导航菜单";
        
        $this->view->tableTile = "导航菜单";     
        
        $nav = new Application_Model_NavMapper();
        $this->view->NavList = $nav->fetchAll();
    }
    
	public function addAction ()
    {    	
    	$layout = $this->_helper->layout();
        $layout->title =  "添加菜单";   
        $layout->keywords = "添加,导航,菜单";
        $layout->description = "添加导航菜单";
        
        $this->view->tableTile = "添加导航菜单";    
        $this->render('edit');
        
    }
    
	public function editAction ()
    {    	
    	$layout = $this->_helper->layout();
        $layout->title =  "修改菜单";   
        $layout->keywords = "修改,导航,菜单";
        $layout->description = "修改导航菜单";
        
        $this->view->tableTile = "修改导航菜单";    

        $NavId = $this->getRequest()->getParam('id');    	
    	if(!is_numeric($NavId))
        	throw new Exception("传值错误:非整型数值!");
        
        $nav = new Application_Model_NavMapper();
        $RealNav = new Application_Model_Nav();
        $nav->find($NavId, $RealNav);
        $this->view->NavEn = $RealNav;
    }
    
	public function saveAction ()
    {     
    	if (!$this->getRequest()->isPost()) {
    		return;
    	}  else	 {
			$request = $this->getRequest();
			
			$NavId = $request->getParam('id');
			$Name = $request->getParam('name');
			$Link = $request->getParam('link');
			$Sort = $request->getParam('sort');
			$Hide = $request->getParam('hide');
			
			$Auto = $request->getParam('auto');
			$Target = $request->getParam('target');
			$Tag = $request->getParam('tag');	        
	        
			$nav = new Application_Model_NavMapper();
	        $EmNav = new Application_Model_Nav();
	        $EmNav->id = $NavId;
	        $EmNav->name = $Name;
	        $EmNav->link = $Link;
	        $EmNav->sort = $Sort;
	        $EmNav->hide = $Hide;
	        $EmNav->auto = $Auto;
	        $EmNav->target = $Target;
	        $EmNav->tag = $Tag; 
	        $nav->save($EmNav);
	        
	        
	        $params = $request->getParams();
	   		$module = $params["module"];
	        $controller = $params["controller"];
	        $action = $params["action"];
	
	        $this->view->targetUrl = $this->getFrontController()->getBaseUrl()."/$module/$controller/";
	        
	        $this->view->state = 1;
	        $this->view->infotitle = '提示';
	        $this->view->message = '提示';
	        $this->render('info');
	        
			/*if ($form->isValid($formData)) {
				$albums = new Albums();
				$row = $albums->createRow();
				$row->artist = $form->getValue('artist');
				$row->title = $form->getValue('title');
				$row->save();
				$this->_redirect('/');
			} else {
				$form->populate($formData);
			}*/
		}
    	
        
    }
    
}
